package com.yunyao.web.controller;


import com.yunyao.common.core.BaseContext;
import com.yunyao.common.core.UserInfoRequest;
import com.yunyao.common.dto.ReceiptSaveDto;
import com.yunyao.common.dto.SubmitReceiptDto;
import com.yunyao.common.web.util.YResult;
import com.yunyao.dao.model.BamuReceipt;
import com.yunyao.dao.service.bamu.IBamuReceiptService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/receipt")
public class ReceiptController {

    @Resource
    private IBamuReceiptService receiptService;

    /**
     * 提交
     *
     * @param dto
     * @return
     */
    @PostMapping("/submitReceipt")
    public YResult<Boolean> submitReceipt(@RequestBody @Valid @NotNull SubmitReceiptDto dto) {
        UserInfoRequest userInfo = BaseContext.getUserInfo();
        dto.setApplyUserId(userInfo.getId());
        dto.setApplyUserName(userInfo.getRealName());
        return YResult.success(receiptService.submitReceipt(dto));
    }


    @PostMapping("/saveOrUpd")
    public YResult<Boolean> saveOrUpd(@RequestBody @Valid @NotNull ReceiptSaveDto dto) {
        return YResult.success(receiptService.saveOrUpd(dto));
    }

    /**
     * 详情
     *
     * @param bizId
     * @param bizType
     * @return
     */
    @GetMapping("/detail")
    public YResult<BamuReceipt> detail(@NotBlank String bizId, @NotBlank String bizType) {
        return YResult.success(receiptService.detail(bizId, bizType));
    }
}
